package manage;

import login.Order;
import login.ajiekou;

import java.util.*;
import java.util.List;

//Order属性管理类

public class OrderSys implements ajiekou<Order> {
    static Map<String, Order> ordermap=new HashMap<>();
    static List<Order>orderlist=new ArrayList<>();
    Scanner sc=new Scanner(System.in);


    @Override
    public void insert(Order order) {
        ordermap.put(order.getoId(),order);
    }

    /*
    通过用户id查询用户的所有订单返回一个list集合
     */
    @Override
    public List<Order> findall() {
        Set<String>keys=ordermap.keySet();//通过键来找键值
        for(String key:keys){
            {
                orderlist.add(ordermap.get(key));
            }
        }
        return orderlist;
    }

    //通过订单ID查找订单
    public List<Order>findByUid(String Uid){
        List<Order>list=new ArrayList<>();
        Set<String>keys=ordermap.keySet();//通过键来找键值
        for(String key:keys){
            if(Objects.equals(Uid,ordermap.get(key).getoId())){
                list.add(ordermap.get(key));
            }
        }
        return list;
    }

    //通过商家来找订单
    public List<Order>findBySlr(String Uid){
        List<Order>list=new ArrayList<>();
        Set<String>keys=ordermap.keySet();//通过键来找键值
        for(String key:keys){
            if(Objects.equals(Uid,ordermap.get(key).getCtm().uID)){
                list.add(ordermap.get(key));
            }
        }
        return list;
    }
    //通过用户来找订单
    public List<Order>findByCtm(String Uid){
        List<Order>list=new ArrayList<>();
        Set<String>keys=ordermap.keySet();//通过键来找键值
        for(String key:keys){
            if(Objects.equals(Uid,ordermap.get(key).getCtm())){
                list.add(ordermap.get(key));
            }
        }
        return list;
    }

    @Override
    public Order findByID(String id) {
        if(ordermap.get(id)==null)
        {
            return null;
        }
        else {
            return ordermap.get(id);
        }
    }

    @Override
    public void delete(String id) {
        //待所有功能完成了就删除订单
    }

    /*@Override
    public void insert(Object o) {
        Order t=(Order) o;//向下转型
        ordermap.put(t.getoId(),t);
    }

    @Override
    public List findall() {
        return null;
    }

    @Override
    public Object findByID(String id) {
        if(ordermap.get(id)==null)
        {
            return null;
        }
        else {
            return ordermap.get(id);
        }

    }

    @Override
    public void delete(String id) {

    }

*/

    //新增订单
}
